package com.tjzx.service;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;

import com.tjzx.common.Pager;
import com.tjzx.dao.EipQuestionInfoDAO;
import com.tjzx.entity.EipQuestionInfo;
public class EipQuestionInfoService {
	private EipQuestionInfoDAO eipQuestionInfoDAO;

	public EipQuestionInfoDAO getEipQuestionInfoDAO() {
		return eipQuestionInfoDAO;
	}

	public void setEipQuestionInfoDAO(EipQuestionInfoDAO eipQuestionInfoDAO) {
		this.eipQuestionInfoDAO = eipQuestionInfoDAO;
	}
	
	public EipQuestionInfo getEipQuestionInfoById(java.lang.Integer id) {
		return eipQuestionInfoDAO.findById(id);
	}
	
	public Pager<EipQuestionInfo> getSuggestions(int pageNo, int pageSize, int firstResult, int maxResults) {
		DetachedCriteria criteria = DetachedCriteria.forClass(EipQuestionInfo.class);
		criteria.add(Property.forName("qtype").eq(2));
		criteria.add(Property.forName("isDel").eq((Boolean.valueOf("false"))));
		criteria.add(Property.forName("isShow").eq((Boolean.valueOf("true"))));
		
		int rowCount = eipQuestionInfoDAO.getCount(criteria);
		criteria.addOrder(Property.forName("questionTime").desc());
		
		List list = eipQuestionInfoDAO.findByCriteria(criteria, firstResult, maxResults);
		return new Pager<EipQuestionInfo>(pageNo, pageSize, rowCount, list);
	}
	public List<EipQuestionInfo> getAll() {
		return eipQuestionInfoDAO.findAll();
	}
	
	public void addQuestionInfo(EipQuestionInfo eipQuestionInfo) {
		eipQuestionInfoDAO.save(eipQuestionInfo);
	}
	
	public void updateQestionInfo(EipQuestionInfo eipQuestionInfo) {
		eipQuestionInfoDAO.merge(eipQuestionInfo);
	}
	
	public void deleteQestionInfo(EipQuestionInfo eipQuestionInfo) {
		eipQuestionInfoDAO.delete(eipQuestionInfo);
	}
}
